<!DOCTYPE html>
<html lang="zh-Hans" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>患者不良孕产史人数统计</title>
    <script src="/static/common/js/echarts.min.js"></script>
    <script src="/static/common/js/common.js"></script>
    <link type="text/css" rel="stylesheet" href="css/countAll.css">
    <div th:replace="cqzd/common/common-resource :: global-header"></div>
</head>
<body>
    <div class="search-condition" style="width:100%;">
            <div id="form1">
                <table style="padding: 5px;" class="table" border="0px" cellspacing="5px" cellpadding="5px" align="center">
                    <tr>
                        <td width="240px">报表类型：
                            <input class="mini-combobox txk-dict" id="statType" dict="CQ_BASE_STAT_TYPE" value="1" onvaluechanged="showDateWidget();"/>
                        </td>
                        <td width="240px">
                            <div id="selectStatType">
                                时间：<input class="mini-datepicker" id="selectTime" format="yyyy/MM/dd"/>
                            </div>
                        </td>
                        <td class="btn-wrap" width="240px">
                            <input class="mini-button" text="查询" onclick="search" iconCls="icon-search"/>
                        </td>
                    </tr>
                </table>
            </div>
        <span id="countVal" style="font-size: 20px;position: relative;right: -85%;font-weight: bold;font-family: '宋体';"></span>

    </div>

<div class="mini-fit" style="padding:10px 5px 5px 5px;">
    <div id="main" style="width: 100%;height: 100%"></div>
</div>

<script type="text/javascript">
    var currentDate = new Date();
    txkui.parse();
    mini.get("selectTime").setValue(currentDate);
    setVisualData();
    var moduleUlr="cqzd/statistics/",modulePageUlr= getHtmlPageUrl("bad_gest_count");

    //根据选择统计类型显示查询时间
    function showDateWidget () {
        var statType=mini.get("statType").value;
        var dayWidget="时间：<input class=\"mini-datepicker\" id=\"selectTime\" value=\""+currentDate+"\" format=\"yyyy/MM/dd\" />";
        var monthWidget="时间：<input class=\"mini-monthpicker\" id=\"selectTime\" value=\""+currentDate+"\" format=\"yyyy/MM\" />";
        var yearWidget="时间：<input class=\"mini-monthpicker\" id=\"selectTime\" value=\""+currentDate+"\" format=\"yyyy\" />";
        switch(statType){
            case "1":
                document.getElementById("selectStatType").innerHTML=dayWidget;
                txkui.parse();
                break;
            case "2":
                document.getElementById("selectStatType").innerHTML=dayWidget;
                txkui.parse();
                break;
            case "3":
                document.getElementById("selectStatType").innerHTML=monthWidget;
                txkui.parse();
                break;
            case "4":
                document.getElementById("selectStatType").innerHTML=monthWidget;
                txkui.parse();
                break;
            case "5":
                document.getElementById("selectStatType").innerHTML=yearWidget;
                txkui.parse();
                break;
            default:
                mini.showTips({
                    content:"统计类型数据错误！",
                    state:"danger",
                    x:"center",
                    y:"top",
                    timeout:3000
                });
                txkui.parse();
        }
    }

    //设置可视化统计数据
    function setVisualData() {
        //1.基于准备好的dom，初始化echarts实例
        var myChart=echarts.init(document.getElementById("main"));

        ////2.指定图表的配置项和数据
        var statType=mini.get("statType").value;
        var title="";    //标题
        var subTitle="";  //副标题
        var countNumber = 0;  //总人数

        var model={};
        var visit=new Array();
        var xAxis= new Array();
        var dict=txkui.getDict("CQ_BASE_BAD_GEST");

        for(var i=0;i<dict.length;i++){
            xAxis[i]=dict[i].text;
        }

        switch(statType){
            case "1":
                title="孕妇患者不良孕产史人数日统计";

                var recordDate=mini.get("selectTime").value.format("yyyy/MM/dd");
                subTitle="统计时间："+recordDate;
                model.recordDay=recordDate;
                $.ajaxSettings.async = false;
                $.post("cqzd/stat/queryBadGestCountByDay",model,function(text){

                    for(var i=0;i<xAxis.length;i++){
                        var badGestObject={};
                        for(var j=0;j<text.data.length;j++){
                            if(xAxis[i]==text.data[j].badGest){
                                badGestObject.value=text.data[j].badGestCount;
                                badGestObject.name=text.data[j].badGest;
                                countNumber += text.data[j].badGestCount;
                                break;
                            }else{
                                badGestObject.value=0;
                                badGestObject.name=xAxis[i];
                            }
                        }
                        visit[i]=badGestObject;
                    }
                    $('#countVal').text('总不良孕产史人数：'+countNumber);
                    return visit;
                });
                $.ajaxSettings.async = true;
                break;
            case "2":
                title="孕妇患者不良孕产史人数周统计";

                var recordDate=mini.get("selectTime").value;
                var endDate=recordDate.format("yyyy/MM/dd");
                var tmpStartDate= new Date();
                tmpStartDate.setTime(recordDate.getTime());
                var startDate= new Date(tmpStartDate.setDate(tmpStartDate.getDate()-6)).format("yyyy/MM/dd");
                subTitle="统计时间："+startDate+" 至 "+endDate;
                model.startDate=startDate;
                model.endDate=endDate;
                $.ajaxSettings.async = false;
                $.post("cqzd/stat/queryBadGestCountByWeek",model,function(text){

                    for(var i=0;i<xAxis.length;i++){
                        var badGestObject={};
                        for(var j=0;j<text.data.length;j++){
                            if(xAxis[i]==text.data[j].badGest){
                                badGestObject.value=text.data[j].badGestCount;
                                badGestObject.name=text.data[j].badGest;
                                countNumber += text.data[j].badGestCount;
                                break;
                            }else{
                                badGestObject.value=0;
                                badGestObject.name=xAxis[i];
                            }
                        }
                        visit[i]=badGestObject;
                    }
                    $('#countVal').text('总不良孕产史人数：'+countNumber);
                    return visit;
                });
                $.ajaxSettings.async = true;


                break;
            case "3":
                title="孕妇患者不良孕产史人数月统计";
                var recordDate=mini.get("selectTime").value;

                model.recordMonth=recordDate.format("yyyy/MM");
                subTitle="统计时间："+model.recordMonth;
                $.ajaxSettings.async = false;
                $.post("cqzd/stat/queryBadGestCountByMonth",model,function(text){

                    for(var i=0;i<xAxis.length;i++){
                        var badGestObject={};
                        for(var j=0;j<text.data.length;j++){
                            if(xAxis[i]==text.data[j].badGest){
                                badGestObject.value=text.data[j].badGestCount;
                                badGestObject.name=text.data[j].badGest;
                                countNumber += text.data[j].badGestCount;
                                break;
                            }else{
                                badGestObject.value=0;
                                badGestObject.name=xAxis[i];
                            }
                        }
                        visit[i]=badGestObject;
                    }
                    $('#countVal').text('总不良孕产史人数：'+countNumber);
                    return visit;
                });
                $.ajaxSettings.async = true;
                break;
            case "4":
                title="孕妇患者不良孕产史人数季统计";
                var recordDate=mini.get("selectTime").value;
                var month=recordDate.format("MM");
                if(month=='01' || month=='02' || month=='03')
                    model.recordQuarter='1'
                if(month=='04' || month=='05' || month=='06')
                    model.recordQuarter='2'
                if(month=='07' || month=='08' || month=='09')
                    model.recordQuarter='3'
                if(month=='10' || month=='11' || month=='12')
                    model.recordQuarter='4'

                model.recordYear=recordDate.format("yyyy");
                subTitle="统计时间：第 "+model.recordQuarter+" 季度";
                $.ajaxSettings.async = false;
                $.post("cqzd/stat/queryBadGestCountByQuarter",model,function(text){

                    for(var i=0;i<xAxis.length;i++){
                        var badGestObject={};
                        for(var j=0;j<text.data.length;j++){
                            if(xAxis[i]==text.data[j].badGest){
                                badGestObject.value=text.data[j].badGestCount;
                                badGestObject.name=text.data[j].badGest;
                                countNumber += text.data[j].badGestCount;
                                break;
                            }else{
                                badGestObject.value=0;
                                badGestObject.name=xAxis[i];
                            }
                        }
                        visit[i]=badGestObject;
                    }
                    $('#countVal').text('总不良孕产史人数：'+countNumber);
                    return visit;
                });
                $.ajaxSettings.async = true;

                break;
            case "5":
                title="孕妇患者不良孕产史人数年统计";
                var recordDate=mini.get("selectTime").value;
                model.recordYear=recordDate.format("yyyy");
                subTitle="统计时间："+model.recordYear+" 年";
                $.ajaxSettings.async = false;
                $.post("cqzd/stat/queryBadGestCountByYear",model,function(text){

                    for(var i=0;i<xAxis.length;i++){
                        var badGestObject={};
                        for(var j=0;j<text.data.length;j++){
                            if(xAxis[i]==text.data[j].badGest){
                                badGestObject.value=text.data[j].badGestCount;
                                badGestObject.name=text.data[j].badGest;
                                countNumber += text.data[j].badGestCount;
                                break;
                            }else{
                                badGestObject.value=0;
                                badGestObject.name=xAxis[i];
                            }
                        }
                        visit[i]=badGestObject;
                    }
                    $('#countVal').text('总不良孕产史人数：'+countNumber);
                    return visit;
                });
                $.ajaxSettings.async = true;
                break;
            default:
                mini.showTips({
                    content:"统计标题数据错误！",
                    state:"danger",
                    x:"center",
                    y:"top",
                    timeout:3000
                });
        }

        var option = {
            title:{
                text:title,
                subtext:subTitle,
                x:"center",
                y:"top"
            },
            legend: {
                orient : 'vertical',       //布局方式:'horizontal' |'vertical'
                x:"right",
                y:"center",
                padding: [
                    5,  // 上
                    100, // 右
                    5,  // 下
                    10, // 左
                ],
                data:xAxis
            },
            tooltip: {
                trigger:'item',
                formatter:"{a} <br/>{b} : {c} ({d}%)"
            },
            toolbox: {
                show : true,
                feature : {
                    dataView : {show: true, readOnly: false},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable:true,
            // Declare several bar series, each will be mapped
            // to a column of dataset.source by default.
            series: [
                {
                    type: 'pie',
                    name:'人数',
                    smooth:true,      //平滑显示
                    showAllSymbol:true,
                    radius:'60%',
                    data:visit
                }
            ]
        };

        //使用刚指定的配置项和数据显示图表
        myChart.setOption(option);
    }


    function search(){
        setVisualData();
    }


</script>

</body>
</html>